package com.derbtec.refale.activities;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.derbtec.refale.R;
import com.derbtec.refale.models.Participant;
import com.derbtec.refale.util.Session;

public class EventParticipantsListViewAdapter extends BaseAdapter {
    private Context context;

    private List<Participant> listParticipant;

    public EventParticipantsListViewAdapter(Context context, List<Participant> listParticipant) {
        this.context = context;
        this.listParticipant = listParticipant;
    }

    public int getCount() {
        return listParticipant.size();
    }

    public Object getItem(int position) {
        return listParticipant.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup viewGroup) {
        Participant entry = listParticipant.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.participant_row, null);
        }
        
        TextView name = (TextView) convertView.findViewById(R.id.tvName);
        name.setText(entry.getUsername());
        
        if(Session.getUserid() == entry.getId())
        	name.setTextColor(Color.parseColor("#00BFFF"));
        else if(entry.isAdmin())
        	name.setTextColor(Color.parseColor("#FF0000"));
        else
        	name.setTextColor(Color.parseColor("#FFFFFF"));
        
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy kk:mm");

        TextView date = (TextView) convertView.findViewById(R.id.tvDate);
        date.setText((df.format(entry.getAcceptdate()).toString()));


        TextView tvfollowers = (TextView) convertView.findViewById(R.id.tvFollower);
        tvfollowers.setText(String.valueOf(entry.getFollowers()));

        return convertView;
    }

}